import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout'
import User from '../views/UserView.vue'
import Personal from '../views/PersonalView.vue'
// 路由表 
Vue.use(VueRouter)

const routes = [
  {
    path: '/signup',
    name: 'signup',
    component: () => import('../views/SignupView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/forget',
    name: 'forget',
    component: () => import('../views/ForgetView.vue')
  },
  {
    path: '/reset',
    name: 'reset',
    component: () => import('../views/ResetView.vue')
  },
  {
    path: '/questionnaire',
    name: 'questionnaire',
    component: () => import('../views/QuestionnaireView.vue')
  },
  //测试组件
  // {
  //   path: '/try',
  //   name: 'try',
  //   component: () => import('../components/Logo.vue')
  // },

  {
    path: '/main',
    component: Layout,//父组件
    // 子组件
    children: [{
      //阅览首页
      path: 'home',
      name: 'home',
      component: () => import('../views/HomeView.vue')
    },
    {
      //推荐中心
      path: 'recommend',
      name: 'recommend',
      component: () => import('../views/RecommendView.vue')
    },
    {
      //题库广场
      path: 'deposit',
      name: 'deposit',
      component: () => import('../views/DepositView.vue')
    },
    {
      //搜索页面
      path: 'search',
      name: 'search',
      component: () => import('../views/SearchView.vue')
    },
    {
      //个人主页
      path: 'user',
      component: User,
      children: [
        {
          //做题情况
          path: 'statistics',
          name: 'statistics',
          component: () => import('../views/User/StatisticsView.vue')
        },
        {
          //做题分析
          path: 'evaluation',
          name: 'evaluation',
          component: () => import('../views/User/EvaluationView.vue')
        },
        {
          //难点回顾
          path: 'difficulty',
          name: 'difficulty',
          component: () => import('../views/User/DifficultyView.vue')
        },
        {
          //收藏题目
          path: 'collection',
          name: 'collection',
          component: () => import('../views/User/CollectionView.vue')
        },
        {
          //历史记录
          path: 'record',
          name: 'record',
          component: () => import('../views/User/RecordView.vue')
        },
        {
          //查看帮助
          path: 'help',
          name: 'help',
          component: () => import('../views/User/HelpView.vue')
        },
      ]
    },
    {
      //编辑个人资料
      path: 'personal',
      component: Personal,
      children: [
        {
          //修改个人信息
          path: 'info',
          name: 'info',
          component: () => import('../views/Personal/ChangeInfoView.vue')
        },
        {
          //修改密码
          path: 'password',
          name: 'password',
          component: () => import('../views/Personal/ChangePasswordView.vue')
        },
      ]
    },
    ]
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}